import fs from "fs";
import path from "path";

export const copyDir = (from, to) => {
  const list = fs.readdirSync(from);
  list.forEach((el) => {
    const subFrom = path.join(from, el);
    const subTo = path.join(to, el);
    if (fs.statSync(subFrom).isDirectory()) {
      if (!fs.existsSync(subTo)) fs.mkdirSync(subTo);
      copyDir(subFrom, subTo);
    } else {
      fs.copyFileSync(subFrom, subTo);
    }
  });
};

export const mkdirs = (location) => {
  if (fs.existsSync(location)) return;
  mkdirs(path.dirname(location));
  fs.mkdirSync(location);
};
